<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/prettyphoto.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.mselect.js?"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.prettyphoto.js"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/json.js"></script>
<script type="text/javascript">
$(function(){
	$("a[rel^='pretty_photo']").prettyPhoto({theme:'facebook'});
	var product_categories_data = <?=$product_categories?>;
	$(document).mselect(product_categories_data, 'product_categories_id', 'product_categories_id', "<?=isset($_GET['product_categories_id']) ? $_GET['product_categories_id'] : 0?>");
	$(document).mselect(product_categories_data, 'move_cat_id', 'move_cat_id', 0);
	$("#check_all").click(function(){
		if ($(this).is(":checked"))
		{
			$(".list_table input[type='checkbox']").attr("checked", true);
		}
		else
		{
			$(".list_table input[type='checkbox']").attr("checked", false);
		}
	});
	$("#export_btn").click(function(){
		var ids = new Array();
		$("#list").find("input[type='checkbox']").each(function(){
			if ($(this).is(":checked"))
			{
				ids.push($(this).val());
			}
		});
		if (ids.length == 0)
		{
			alert("请选择产品");
			return false;
		}
		$("#ids").val($.toJSON(ids));
		$("#action_form").attr("action", "<?=url('Product::Basicinfo/ExportChecked')?>").submit();
	});
	$("#export_search_btn").click(function(){
		$("#action_form").attr("action", "<?=url('Product::Basicinfo/ExportSearch')?>").submit();
	});
	$("#upload_file_btn").click(function(){
		$("#upload_form").submit();
	});
	$("#print_btn").click(function(){
		var ids = new Array();
		$("#list").find("input[type='checkbox']").each(function(){
			if ($(this).is(":checked"))
			{
				ids.push($(this).val());
			}
		});
		if (ids.length == 0)
		{
			alert("请选择产品");
			return false;
		}
		$("#ids").val($.toJSON(ids));
		$("#action_form").attr("action", "<?=url('Product::Basicinfo/Print')?>").attr("target", "_blank").submit();
		$("#action_form").attr("target", "");
	});
	$("#create_image_requirement_btn").click(function(){
		var ids = new Array();
		$("#list").find("input[type='checkbox']").each(function(){
			if ($(this).is(":checked"))
			{
				ids.push($(this).val());
			}
		});
		if (ids.length == 0)
		{
			alert("请选择产品");
			return false;
		}
		$("#ids").val($.toJSON(ids));
		$("#action_form").attr("action", "<?=url('Product::Image/Create')?>").submit();
	});
	$("#move_btn").click(function(){
		var ids = new Array();
		$("#list").find("input[type='checkbox']").each(function(){
			if ($(this).is(":checked"))
			{
				ids.push($(this).val());
			}
		});
		if (ids.length == 0)
		{
			alert("请选择产品");
			return false;
		}
		move_cat_id = $("#move_cat_id").val();
		if (! move_cat_id)
		{
			alert('请选择移动分类');
			return false;
		}
		if (! confirm('确定按勾选移动分类？'))
		{
			return false;
		}
		$("#ids").val($.toJSON(ids));
		$("#form_move_cat_id").val($.toJSON(move_cat_id));
		$("#action_form").attr("action", "<?=url('Product::Basicinfo/MoveCategoriesChecked')?>").submit();
	});
	$("#move_search_btn").click(function(){
		move_cat_id = $("#move_cat_id").val();
		if (! move_cat_id)
		{
			alert('请选择移动分类');
			return false;
		}
		if (! confirm('确定按条件移动分类？'))
		{
			return false;
		}
		$("#form_move_cat_id").val($.toJSON(move_cat_id));
		$("#action_form").attr("action", "<?=url('Product::Basicinfo/MoveCategoriesSearch')?>").submit();
	});
});
</script>
<fieldset><legend>查询条件</legend>
<form action="" method="get">
<? include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
	<table class="form_table">
		<tr>
			<th>产品编号</th>
			<td>
				<input type="text" name="start_number" value="<?=isset($_GET['start_number']) ? $_GET['start_number'] : ''?>" />
				<!-- <input type="text" name="end_number" value="<?=isset($_GET['end_number']) ? $_GET['end_number'] : ''?>" />  --> 前置模糊搜索: A...
			</td>
		</tr>
		<tr>
			<th>产品名称</th>
			<td>
				<input type="text" name="name" value="<?=isset($_GET['name']) ? $_GET['name'] : ''?>" />
			</td>
		</tr>
		<tr>
			<th>供应商名称</th>
			<td>
				<input type="text" name="preferred_provider_name" value="<?=isset($_GET['preferred_provider_name']) ? $_GET['preferred_provider_name'] : ''?>" />
			</td>
		</tr>
		<tr>
			<th>多个编号</th>
			<td>
				<input type="text" name="product_numbers" value="<?=isset($_GET['product_numbers']) ? $_GET['product_numbers'] : ''?>" size="80" />
			</td>
			<td>说明：多个产品编号用英文逗号分开</td>
		</tr>
		<tr>
			<th>选择分类</th>
			<td><input type="hidden" id="product_categories_id" name="product_categories_id" /></td>
		</tr>
		<tr>
			<th>跟进人</th>
			<td>
				<select name="follow_user_id">
				<option></option>
				<?foreach ($user as $u):?>
				<option value="<?=$u['id']?>" <?if (isset($_GET['follow_user_id']) && $u['id'] == $_GET['follow_user_id'])echo "selected='selected'"?>><?=$u['name']?></option>
				<?endforeach;?>				
				</select>
			</td>
		</tr>
		<tr>
			<th>筛选</th>
			<td>
				<label><input type="checkbox" name="undone" <?if (isset($_GET['undone']))echo "checked=checked";?>/> 资料不全</label>
				<label><input type="checkbox" name="no_follow_user" <?if (isset($_GET['no_follow_user']))echo "checked=checked";?>/> 未跟进</label>
				<label><input type="checkbox" name="is_diff_flag" value="1" <?if (!empty($_GET['is_diff_flag']))echo "checked='checked'"?>/> 采购价≠最近采购价</label>
			</td>
		</tr>
		<tr>
			<td></td>
			<td><input type="submit" id="submit" class="button" value="查询" /></td>
		</tr>
	</table>
</form>
</fieldset>
<table width="100%" class="list_table" id="list">
	<tr>
		<th width="100">产品编号</th>
		<th>产品名称</th>
		<th width="45">图片</th>
		<th width="100">采购价</th>
		<th width="100">最近采购价</th>
		<th width="100">重量(g)</th>
		<th>首选供应商</th>
		<th>跟进人</th>
		<th width="100">操作</th>
	</tr>
	<? foreach ($product as $p): ?>
	<tr>
		<td><label><input type="checkbox" value="<?=$p['id']?>" /> <?=$p['number']?></label></td>
		<td align="left"><a href="<?=url('Product::Basicinfo/View', array('id' => $p['id']))?>"><?=$p['name']?></a></td>
		<td>
			<?if ($p['pic_url']):?>
				<?$pretty_photo_number = 0;?>
				<?foreach ($p['pic_url'] as $pp):?>
				<a rel="pretty_photo[<?=$p['id']?>]" href="<?=$pp?>"><?if(!$pretty_photo_number):?><span class="img_icon"></span><?endif;?></a>
				<?$pretty_photo_number = 1;?>
				<?endforeach;?>
			<?endif;?>
		</td>
		<td><?=sprintf('%.2f', $p['purchase_price'])?></td>
		<td><?=sprintf('%.2f', $p['last_purchase_price'])?></td>
		<td><?=sprintf('%.0f', $p['weight'])?></td>
		<td><?=$p['preferred_provider_name']?></td>
		<td><?=$p['follow_user_name']?></td>
		<td><a href="<?=url('Product::Basicinfo/edit', array('id' => $p['id']))?>">编辑</a></td>
	</tr>
	<? endforeach;?>
</table>
<?=$page?>
<table class="list_table">
	<tr>
		<td rowspan="5"><label><input type="checkbox" id="check_all" /> 全选</label></td>
		<td align="left">
			<form id="upload_form" action="<?=url('Product::Basicinfo/Import')?>" method="post" enctype="multipart/form-data">
				导入基本资料：<input type="file" name="product_file" />
				<input type="button" class="button" id="upload_file_btn" value="导入" />
			</form>
		</td>
	</tr>
	<tr>
		<td align="left">导出：
			<input type="button" class="button" id="export_btn" value="按勾选" />
			<input type="button" class="button" id="export_search_btn" value="按条件" />
		</td>
	</tr>
	<tr>
		<td align="left">移动分类：
			<input type="hidden" id="move_cat_id" />
			<input type="button" class="button" id="move_btn" value="按勾选" />
			<input type="button" class="button" id="move_search_btn" value="按条件" />
		</td>
	</tr>
	<tr>
		<td align="left">打印：
			<input type="button" class="button" id="print_btn" value="按勾选" />
		</td>
	</tr>
	<tr>
		<td align="left">创建图片需求单：
			<input type="button" class="button" id="create_image_requirement_btn" value="按勾选" />
		</td>
	</tr>
</table>
<form id="action_form" action="" method="post" target="">
	<input type="hidden" name="url_arr" value='<?=$url_arr?>' />
	<input type="hidden" id="ids" name="ids" value="" />
	<input type="hidden" name="form_move_cat_id" id="form_move_cat_id" value="" />
</form>
<?php $this->_endblock(); ?>